package com.example.mapp;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import com.example.entity.authority.PartyUser;

import java.util.List;
import java.util.Map;

/**
 * Created by youkun on 2017/9/15.
 */
@Mapper
public interface PartyUserMapp {

    @Insert("insert into party_user (party_id,user_id) value (#{partyId},#{userId})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    int insert(PartyUser partyUser) throws Exception;

    @Delete("delete from party_user where user_id=#{userId}")
    int deleteByUserId(String userId) throws Exception;

    @Select(" select * from party_user where user_id = #{userId}")
    PartyUser findById(String userId) throws Exception;

    @Select(" select * from party_user where party_id=#{partyId}")
    List<PartyUser> findByPartyId(String partyId) throws Exception;

    @Select(" select a.* from party_user as a inner join sys_user as b  on a.user_id = b.id where a.party_id=#{partyId} and b.type='user' ")
    List<PartyUser> findByPartyIdAndType(String partyId) throws Exception;


}
